﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace CIRDiagnoseDevice
{
    public partial class Login : Form
    {
        public static Login logon;
        MainFrm mainForm;
        public Login()
        {
            mainForm = new MainFrm();
            logon =this;
            InitializeComponent();
        }

        public OleDbConnection DbConnection()
        {
            string conStr = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source =" + Application.StartupPath + @"\" + "UserInfo.accdb" + "; Jet OLEDB:Database Password = 430510;";
            OleDbConnection conn = new OleDbConnection(conStr);

            return conn;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (User.Text != "")
            {
                OleDbConnection conn = DbConnection();
                string querylan = "Select 用户名 ,密码 From UserInfo Where 用户名='" + User.Text.Trim() + "'" + "And 密码='" + PW.Text.Trim() + "'";
                OleDbCommand command = new OleDbCommand(querylan, conn);
                command.CommandType = CommandType.Text;
                try
                {
                    conn.Open();
                    OleDbDataReader reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                         DialogResult = DialogResult.OK;
                        label4.Text = "";
                        label3.Text = "";
                        mainForm.Show();
                        this.Hide();
                    }
                    else
                    {
                        label15.Text = "用户名或密码错误";
                    }
                }
                catch
                {

                }
            }
            else
            {
                MessageBox.Show("用户名不能为空！");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            DialogResult = DialogResult.Cancel;
        }

        private void Logon_Load(object sender, EventArgs e)
        {
          //  User.Text = UserName;
            User.Focus();
        }
    }
}
